package solution;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-05-11
 * Time: 15:07
 */
//https://leetcode.cn/problems/qJnOS7/submissions/431601145/
    //字符串的子序列，一定要理解定义
public class Solution6 {
}
class solution {
    public int longestCommonSubsequence(String text1, String text2) {
        int s1 = text1.length();
        int s2 = text2.length();
        int[][] dp = new int[s1 + 1][s2 + 1];
        for (int i = 1; i <= s1; i++) {
            char a = text1.charAt(i - 1);
            for (int j = 1; j <= s2; j++) {
                char b = text2.charAt(j - 1);
                if (a == b) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                } else {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }
        return dp[s1][s2];
    }
}
